
const { join } = require('path')

const paths = {
  root: join(__dirname, '..'),
  src: join(__dirname, '..', 'src'),
  dist: join(__dirname, '..', 'dist')
}

module.exports = {
  paths,

  entry: {
    main: join(paths.src, 'index')
  },

  output: {
    path: paths.dist,
    filename: '[name]-[chunkhash].js'
  },

  htmlPluginConfig: {
    title: 'react-startkit',
    template: join(paths.src, 'html', 'template.html')
  },

  standardPreLoader: {
    enforce: 'pre',
    test: /\.js$/,
    include: paths.src,
    use: 'standard-loader'
  },
  // copyPluginConfig: {
  //   patterns: [
  //     { from: join(paths.example, 'public'), to: './public' },
  //     {
  //       from: join(paths.example, 'container/*/*.md'),
  //       to: './docs/[1]/[2].[ext]',
  //       test: /container[\\/]{1}(.+)[\\/]{1}(.+)\.md$/,
  //       toType: 'template'
  //     }
  //   ],
  // },
  jsLoader: {
    test: /\.js$/,
    include: paths.src,
    use: ['react-hot-loader/webpack', {
      loader: 'babel-loader',
      options: {
        presets: [['env', { modules: false }], 'stage-0', 'react'],
        plugins: [
          ['transform-runtime', {
            helpers: false,
            polyfill: false,
            regenerator: true
          }]
        ]
      }
    }]
  },

  cssLoader: {
    test: /\.css$/,
    use: [
      'style-loader',
      'css-loader'
    ]
  },
  lessLoader: {
    test: /\.less$/,
    use: [
      'style-loader',
      'css-loader?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]',
      'less-loader'
    ]
  },
  fileLoader: {
    test: /\.(ico|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|txt)(\?.*)?$/,
    include: paths.src,
    use: 'file-loader?name=[sha512:hash:base64:7].[ext]&publicPath=/media/&outputPath=media/'
  },
  urlLoader: {
    test: /\.(mp4|webm|wav|mp3|m4a|aac|oga)(\?.*)?$/,
    include: paths.src,
    use: {
      loader: 'url-loader',
      query: {
        limit: 10000,
        name: 'media/[name].[hash:8].[ext]'
      }
    }
  },
  resolve: {
    alias: {
      src: paths.src,
      components: join(paths.src, 'components'),
      containers: join(paths.src, 'containers'),
      utils: join(paths.src, 'utils'),
      'server-apis': join(paths.src, 'server-apis'),
      media: join(paths.src, 'media')
    }
  }
}
